package com.bflow.web.controller.gtasks;

import com.bflow.api.IBflowDefineActService;
import com.bflow.api.IBflowRunTaskService;
import com.bflow.api.bo.BflowDefineActBo;
import com.bflow.api.bo.BflowDefineActQueryParam;
import com.bflow.api.bo.BflowWaitDisposeBo;
import com.bflow.api.bo.ext.BflowUserBo;
import com.bflow.api.constant.BflowConstant;
import com.bflow.commons.bean.PageResult;
import com.bflow.commons.bean.TableResult;
import com.bflow.commons.consts.CommConst;
import com.bflow.util.AssertUtil;
import com.bflow.util.JsonUtil;
import com.bflow.web.controller.BflowBaseController;
import com.bflow.web.util.RequestUtil;
import com.bflow.web.util.TestLoginUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * @Name 待办
 * @Author hch
 */
@Controller
@RequestMapping(value = "/bflow/gtasks")
public class GtasksController extends BflowBaseController {

    @Autowired
    private IBflowDefineActService<?, BflowDefineActBo> bflowDefineActService;

    @Autowired
    private IBflowRunTaskService bflowRunTaskService;

    @RequestMapping(value = "list")
    @ResponseBody
    public String list(BflowDefineActQueryParam queryParam, HttpServletRequest req, HttpServletResponse resp) {
        try {
            BflowUserBo user = TestLoginUtil.getUser(req);
            AssertUtil.isNotNull(user, "您还未登录, 请先登录");
            PageResult<BflowDefineActBo>  pageResult = bflowDefineActService.findPage(queryParam);
            BflowWaitDisposeBo waitDisposeTaskList = bflowRunTaskService.getWaitDisposeTaskList(user.getUserId(), null, null,user.getRoleKey());
            if(waitDisposeTaskList==null){
                return JsonUtil.toStr(new TableResult(null,0));
            }
            TableResult result=new TableResult(waitDisposeTaskList.getTasks(),waitDisposeTaskList.getTasks().size());
            return JsonUtil.toStr(result);
        } catch (Exception e) {
            e.printStackTrace();
            return returnFail(e, "待办列表查询失败");
        }
    }

}
